Tiny Hexer Script: Functions

This page shows all available Tiny Hexer Script functions. Note: As of version 1.6.0.2 of Tiny Hexer most functions can be used like commands, i. e. functions which have no equally named command counterpart can be used as first keyword in a script line (in this case the function's result is discarded).


top bottom
# A B C D E F G H I L M O P R S T W

top bottom
NUMBER ABS(number)*
Parameters:

number: a numeric expression

more...

less...

ABS() returns the absolute value of the argument number
Sample:
VAR float DOUBLE integer SIGWORD

float   = ABS(-2.5):=  returns 2.5
integer = ABS(-4711):= returns 4711

MSGBOX (TEXT(float)+', '+DEC(integer))

top bottom
EXTENDED ARCCOS(number)*
Parameters:

number: a floating point expression

more...

less...

ARCCOS() returns the arcus cosine of the argument number (range -1..1). The result is in the range 0..PI.

top bottom
EXTENDED ARCSIN(number)*
Parameters:

number: a floating point expression

more...

less...

ARCSIN() returns the arcus sine of the argument number (range -1..1). The result is in the range -PI//2..PI//2.

top bottom
EXTENDED ARCTAN(number)*
Parameters:

number: a floating point expression

more...

less...

ARCTAN() returns the arcus tangent of the argument number. The result is in the range -PI//2..PI//2.

top bottom
TEXT ASKDIRECTORY([title [, selection]])*
Parameters:

title, selection: optional TEXT expressions

more...

less...

Use the ASKDIRECTORY() function to let the user select a directory from a dialog.

The optional title parameter sets the title of the directory selection dialog.

The optional selection parameter tells Tiny Hexer which directory should be selected when the dialog is shown (on some versions of Windows this will not work).

Note: If the user chooses the "Cancel" button in the directory selection dialog, the script will be terminated if no error handler is set.
See also: ASKOPENFILENAME(), ASKSAVEFILENAME().
Sample:
= select a directory and display it in a message box
VAR dir TEXT

LET dir = ASKDIRECTORY('Please choose a directory', 'c:\')

MSGBOX ('You selected the directory '+dir)

top bottom
BYTE ASKFINDOPTIONS(caption, searchdata_ref, istext_ref, ignorecase_ref, wildcard_ref)*
Parameters:

caption: a TEXT expression
searchdata_ref, istext_ref, ignorecase_ref, wildcard_ref: expressions of type VARREF

more...

less...

Use the ASKFINDOPTIONS() function to let the user choose search options in a find dialog.

If the User clicks the Cancel button, the function returns 0, otherwise 1 is returned and the find options are stored in the variables referenced by the *_ref expressions:

searchdata_ref must refer to a TEXT variable that will be set to the text to search for.

istext_ref must refer to a BYTE variable set to the value of the "Find Text" and "Regular Expression" checkboxes (2 if "Regular Expression" is checked, 1 if "Find Text" is checked, 0 otherwise).

ignorecase_ref must refer to a BYTE variable set to the value of the "Ignore Case" checkbox.

wildcard_ref must refer to a TEXT variable that is set to the wildcard text if the user checked the "Wildcard" checkbox, otherwise, it's set to an empty string.
Sample:
= search for all occurences of a string in the current file, store
= the results in the position list and save the positions list to disk

= query find options
var f_Text TEXT, f_FindText BYTE, f_IgnoreCase BYTE, f_Wildcard TEXT
if (not AskFindOptions("Search the whole file and save results", @f_Text, @f_FindText, @f_IgnoreCase, @f_Wildcard))
  end
endif

= query file name for list saving
var res_file TEXT
res_file = AskSaveFileName("Choose name of search results file", 'Text Files (*.txt)|*.txt')

= clear current contents of the position list
if (POSITION_COUNT)
  !CMD.PosList.PosListSelectAll
  !CMD.PosList.PosListDeleteSelected
endif

= find all and store in the position list
!CMD.EditFindStore f_text, f_ignorecase, f_findtext, f_wildcard

if (not POSITION_COUNT)
  = not found
  error "Data not found!"
else
  = save
  POSITION_DESC = ("Search results for: "+f_text+" on "+CURRENTFILE)
  !CMD.PosList.PosListSave res_file
endif
TEXT ASKOPENFILENAME([caption [, filter [, default ]]])*
Parameters:

caption, filter, default: optional TEXT expressions

more...

less...

Use the ASKOPENFILENAME() function to let the user select a filename for file loading.

The optional caption parameter sets the title of the file selection dialog.

The optional filter parameter tells Tiny Hexer what file types to display in the file selection dialog. This parameter is a TEXT string in the form of "Description|File mask[|...]" (e.g. "Text files|*.txt|All files|*.*").

The optional default parameter tells Tiny Hexer the initial filename to be used when displaying the dialog.

Note: If the user chooses the "Cancel" button in the file dialog, the script will be terminated if no error handler is set.
See also: ASKDIRECTORY(), ASKSAVEFILENAME().
Sample:
= select a file and print it via notepad
VAR fname TEXT

LET fname = ASKOPENFILENAME('Print a Text file', 'Text Files (*.txt)|*.txt')

SHELL 'notepad.exe',  ('/p "'+fname+'"')

top bottom
TEXT ASKSAVEFILENAME([caption [, filter [, defext [, default ]]]])*
Parameters:

caption, filter, defext, default: optional TEXT expressions

more...

less...

Use the ASKSAVEFILENAME() function to let the user select a filename for file storing.

The optional caption parameter sets the title of the file selection dialog.

The optional filter parameter tells Tiny Hexer what file types to display in the file selection dialog. This parameter is a TEXT string in the form of "Description|File mask[|...]" (e.g. "Text files|*.txt|All files|*.*").

The optional defext parameter tells Tiny Hexer which filename extension to use if none is entered in the dialog.

The optional default parameter tells Tiny Hexer the initial filename to be used when displaying the dialog.

Note: If the user chooses the "Cancel" button in the file dialog, the script will be terminated if no error handler is set.
See also: ASKDIRECTORY(), ASKOPENFILENAME().
Sample:
= save the current selection to disk
VAR selname TEXT

IF CURRENTFILE == ''
  ERROR 'No open file'
ENDIF

LET selname = ASKSAVEFILENAME('Save current selection', 'All Files (*.*)|*.*')

!CMD.FileSaveSelection selname

top bottom
TEXT BIN(number [, usetype])
Parameters:

number: an ordinal expression
usetype: an optional expression of type BYTE

more...

less...

Use the BIN() function to convert the ordinal numeric expression number to a binary representation consisting of the characters "0" and "1". If the optional parameter usetype is set to 0, numbers < 0 are always converted as 64 bits signed values. If set to 1, the type of number is used to convert negative values. This flag affects the converted representation of negative values only, positive values are always calculated using the original data type.
See also: DEC(), HEX(), OCT().
Sample:
MSGBOX (BIN(BYTE(1))):= shows "00000001" (8 bits)
MSGBOX (BIN(WORD(256))):= shows "0000000100000000" (16 bits)
MSGBOX (BIN(LONGWORD(256))):= shows "00000000000000000000000100000000" (32 bits)
MSGBOX (BIN(SIGBYTE(-1))):= shows "1111111111111111111111111111111111111111111111111111111111111111" (64 bits)
MSGBOX (BIN(SIGBYTE(-1),1)):= shows "11111111" (8 bits)
MSGBOX (BIN(SIGWORD(-1),1)):= shows "1111111111111111" (16 bits)

top bottom
TEXT BIN2HEX(strdata [, swaphalfbytes])
Parameters:

strdata: an expression of type TEXT
swaphalfbytes: an optional expression of type BYTE

more...

less...

The BIN2HEX() function is used to convert the binary contents of the expression strdata to their hexadecimal text representation, i.e. each byte is converted to two hexadecimal digits.

If the optional paramater swaphalfbytes is set to 1, the order of the returned values is <low halfbyte><high halfbyte>..., otherwise the order is <high halfbyte><low halfbyte>...
See also: HEX2BIN().
Sample:
= convert data to hexadecimal digits
VAR txt1 TEXT txt2 TEXT

txt1 = 'ABC'

LET txt2 = BIN2HEX(txt1)
= txt2 now contains '414243'

MSGBOX txt2

LET txt2 = BIN2HEX(txt1, 1)
= txt2 now contains '142434'

MSGBOX txt2

top bottom
BYTE BYTE(expr)
Parameters:

expr: an expression

more...

less...

The BYTE() function is used to convert the expression expr to the BYTE data type.

If expr is a numeric or CHAR expression, the lowest eight bits of its ordinal value are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest eight bits of the converted number are returned.
See also: Data types.
Sample:
= show the ascii value of a char
VAR ch CHAR inp TEXT bt BYTE

REPEAT
  inp = INPUT('Enter a character', '', 'A')
UNTIL TEXTLEN(inp) == 1

LET ch = inp

LET bt = BYTE(ch)

MSGBOX ('The ASCII value of '+inp+' is '+TEXT(bt))

top bottom
LONGWORD BYTESTRING(text)
Parameters:

text: a textual expression

more...

less...

The BYTESTRING() function tries to convert the text text to a byte value.
Sample:
= convert some byte strings
VAR s1 TEXT s2 TEXT s3 TEXT
VAR res LONGWORD

LET s1 = "2.5 GB"
LET s2 = "512k"
LET s3 = "8 MEGABYTE"

LET res = BYTESTRING(s1)
= res contains the value 2.5 * 1024 * 1024 * 1024 = 2684354560
MSGBOX DEC(res)

LET res = BYTESTRING(s2)
= res contains the value 512 * 1024 = 524288
MSGBOX DEC(res)

LET res = BYTESTRING(s3)
= res contains the value 8 * 1024 * 1024 = 8388608
MSGBOX DEC(res)

top bottom
VALUE CALL(target [, param1, param2...])
VALUE #target [( param1, param2...)]
Parameters:

target: the name of a label in the current script (in the form of a TEXT expression if the CALL() construct is used)
param1/2...: optional expressions that are pushed to the stack

more...

less...

The CALL() function is used to execute a user defined subroutine in the current script at the label target. The subroutine should return a value using the RETURN command. This value is used as the function's value. Contrary to the CALL command, the label's name must be specified using a textual expression, so the CALL() function is slower than the CALL command as the position of the label target is looked up from a table at runtime rather than at compile time. But the function is also more flexible as the label can be changed at runtime. Note: As of version 1.7 of Tiny Hexer, you can use the #target construct to avoid label name lookups at runtime. This construct can only be used with labels that are already defined.

The CALL() function can have optional parameters that are pushed to the stack. The subroutine can retrieve those parameters using the POP command. (Note: Because the stack is a LIFO, the first POP in a subroutine returns the last parameter, the second POP returns the last but one parameter...). The subroutine can retrieve the number of parameters pushed to the stack by reading the ARGC special variable.
See also: CALL, LABEL, LOCAL...ENDLOCAL,RETURN, ARGC special variable, POP, OPTION GLOBALVARS directive.
Sample:
= SAMPLE 1 = calculating the factorial using recursive function calls


= recursive factorial function
LOCAL factorial
  VAR fac SIGQWORD n SIGQWORD

  POP n
  fac = 1
  IF (n > 1)
    fac = n * #factorial(n-1)
  ENDIF
  RETURN fac
ENDLOCAL

VAR num BYTE

@@loop1
num=INPUTNUMBER('Factorial', 'Enter a number between 0 and 20:',20)
= 21! and above do not fit into 63 Bits
IF (num > 20):GOTO loop1:ENDIF

MSGBOX (DEC(num)+'! = '+DEC(#factorial(num)))
END



= SAMPLE 2 = showing the usage of CALL(), ARGC, TYPEOFSTACK, POP, RETURN


INCLUDE 'DEF.MPS'
OPTION GLOBALVARS, 0

= pop a value from the stack, ensure it is text
LOCAL poptext
  VAR result TEXT stacktype BYTE
  = get the type of the data on stack
  stacktype=TYPEOFSTACK:= store the stack data type in a local variable before using it in complex expressions!


  IF ((stacktype == SINGLE_DATA) OR (stacktype == COMP_DATA) OR (stacktype == DOUBLE_DATA)  OR (stacktype == EXTENDED_DATA))
    = handle floating point expressions
    VAR ftemp EXTENDED
    POP ftemp
    result = TEXT(ftemp)
  ELSE
    IF ((stacktype != CHAR_DATA) AND (stacktype != TEXT_DATA))
      = seems to be a number, so pop the number and convert to text
      VAR temp SIGQWORD
      POP temp
      result = DEC(temp)
    ELSE
      = is text, pop directly from stack
      POP result
    ENDIF
  ENDIF
  = return the data as text
  RETURN result
ENDLOCAL

LOCAL args
  VAR argt TEXT
  = check the number of parameters pushed to the stack by the caller
  IF ARGC > 0
    = pop the value from the stack, ensure it's of type TEXT
    argt = #poptext
    = pop remaining data to cleanup stack
    IF ARGC > 1
      LOOP poptext, ARGC-1
    ENDIF
  ENDIF
  RETURN (DEC(argc)+' arguments, last argument: '+argt)
ENDLOCAL

VAR t TEXT
t="I am variable t"
MSGBOX #args:= call the local sub 'args', no parameters
MSGBOX CALL('args','text'):= call the local sub 'args', one text parameter
MSGBOX #args('text',2):= call the local sub 'args', text and numeric parameter
MSGBOX #args('text',8,-3.98):= call the local sub 'args', text, ordinal and float parameter
MSGBOX CALL('args','text',2,'hey!',5.8,t):= call the local sub 'args', mixed parameters

top bottom
SIGLONGWORD CEIL(number)*
Parameters:

number: a numeric expression

more...

less...

CEIL() returns the ordinal value of the argument number, rounded towards infinity.
See also: FLOOR(), FRAC(), INT(), ROUND(), TRUNC().
Sample:
MSGBOX (DEC(CEIL(2.0))):= results in "2"
MSGBOX (DEC(CEIL(2.0001))):= results in "3"
MSGBOX (DEC(CEIL(-2.0001))):= results in "-2"

top bottom
CHAR CHAR(expr)
Parameters:

expr: an expression

more...

less...

The CHAR() function is used to convert the expression expr to the CHAR data type.

If expr is a numeric expression, the lowest eight bits of its ordinal value are converted to a character and are returned.

If expr is of type TEXT, the first character of the string is returned. If the string is empty, an error is raised.
See also: Data types.
Sample:
= show the character representing an ascii value
VAR ch CHAR num BYTE inp TEXT

REPEAT
  REPEAT
    inp = INPUT('Enter an ASCII value between 33 and 127', '', '65')
  UNTIL ISNUMBER(inp)
  LET num = BYTE(inp)
UNTIL (num > 32) AND (num < 128)

LET ch = CHAR(num)

MSGBOX ('Character: "'+ch+'"')

top bottom
COMP COMP(expr)
Parameters:

expr: an expression

more...

less...

The COMP() function is used to convert the expression expr to the COMP data type.

If expr is a numeric or CHAR expression, its ordinal numeric value is returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a 64 bits signed number. If conversion fails, an error is raised.
See also: Data types.
Sample:
VAR inp TEXT co COMP

REPEAT
  inp = INPUT('Enter a number')
UNTIL ISNUMBER(inp)

LET co = COMP(inp)

MSGBOX ('The number you entered was: '+TEXT(co))

top bottom
LONGWORD COMPARE_END(index)*
Parameters:

index: a numeric expression

more...

less...

The COMPARE_END() function returns the position of the last byte of difference block #index (first block is at index 0) after a file comparison has been executed.
See also: File comparison, COMPARE_COUNT special variable, COMPARE_START().

top bottom
LONGWORD COMPARE_START(index)*
Parameters:

index: a numeric expression

more...

less...

The COMPARE_START() function returns the position of the first byte of difference block #index (first block is at index 0) after a file comparison has been executed.
See also: File comparison, COMPARE_COUNT special variable, COMPARE_END().

top bottom
EXTENDED COS(number)*
Parameters:

number: a floating point expression

more...

less...

COS() returns the cosine of the argument number (radian).

top bottom
EXTENDED COT(number)*
Parameters:

number: a floating point expression

more...

less...

COT() returns the cotangent of the argument number (radian).

top bottom
TEXT DATA2TEXT(expr)
Parameters:

expr: an expression

more...

less...

The DATA2TEXT() function is used to store the binary value of expression expr in a data of type TEXT.

It e.g. can be used to create tables of multiple numeric values by storing them in a single TEXT string.
See also: TEXT2DATA(), DATA2TEXTBE().
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1

VAR ptable TEXT, num SIGQWORD

= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
  CONCAT ptable, DATA2TEXT(SIGQWORD(num))
  INC num, num
ENDLOCAL


VAR inp TEXT q SIGQWORD power SIGQWORD

LET num = 1
LET ptable = ''
LOOP create_table 63

REPEAT
  REPEAT
    REPEAT
      LET inp = INPUT('Enter a number between 0 and 62')
    UNTIL ISNUMBER(inp)
    LET q = SIGQWORD(inp)
  UNTIL (q < 63) AND (q >= 0)

  = power values are stored as SIGQWORD, so SIGQWORD_SIZE must be used
  = to access the correct data
  power = TEXT2DATA(ptable, q, SIGQWORD_SIZE)
  MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))

UNTIL 0

top bottom
TEXT DATA2TEXTBE(expr)
Parameters:

expr: an expression

more...

less...

The DATA2TEXTBE() function is used to store the binary value of expression expr in a data of type TEXT in BIG ENDIAN format (used e.g. by Motorola CPUs).

It e.g. can be used to create tables of multiple numeric values by storing them in a single TEXT string.
See also: TEXT2DATABE(), DATA2TEXT().
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1

VAR ptable TEXT, num SIGQWORD

= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
  CONCAT ptable, DATA2TEXTBE(SIGQWORD(num))
  INC num, num
ENDLOCAL


VAR inp TEXT q SIGQWORD power SIGQWORD

LET num = 1
LET ptable = ''
LOOP create_table 63

REPEAT
  REPEAT
    REPEAT
      LET inp = INPUT('Enter a number between 0 and 62')
    UNTIL ISNUMBER(inp)
    LET q = SIGQWORD(inp)
  UNTIL (q < 63) AND (q >= 0)

  = power values are stored as SIGQWORD, so SIGQWORD_SIZE must be used
  = to access the correct data
  power = TEXT2DATABE(ptable, q, SIGQWORD_SIZE)
  MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))

UNTIL 0

top bottom
TEXT DEC(number)
Parameters:

number: an ordinal expression

more...

less...

Use the DEC() function to convert the ordinal numeric expression number to a textual decimal representation consisting of the characters "0".."9". Numbers < 0 are prefixed by a "-" (minus) sign.
See also: BIN(), HEX(), OCT().
Sample:
MSGBOX (DEC(BYTE(1))):= shows "1" (8 bits)
MSGBOX (DEC(WORD(256))):= shows "256" (16 bits)
MSGBOX (DEC(LONGWORD(256))):= shows "256" (32 bits, but msbs set to 0)
MSGBOX (DEC(SIGBYTE(-1))):= shows "-1" (8 bits)
MSGBOX (DEC(SIGWORD(-1))):= also shows "-1" (16 bits)
MSGBOX (DEC(LONGWORD(-1))):= shows "4294967295" (32 bits, unsigned)

top bottom
VAR DEREF(reference)
Parameters:

reference: a variable of type VARREF

more...

less...

The DEREF() function is used to retrieve the referenced variable stored in reference.

The function is used to e.g. pass data of arbitrary data types to a subroutine. To create references to variables, use the unary reference operator @.
See also: VARREF data type, unary reference operator @, TYPEOF().
Sample:
= show data type example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1

VAR output TEXT

= get a textual data type representation
LOCAL getdatatype
  VAR stack VARREF
  VAR type SIGBYTE
  VAR types TEXT
  LET types = <<
none
character
unsigned byte
unsigned word
unsigned long
signed quad
text
file
variable reference
single float
double float
extended float
comp float
signed byte
signed word
signed long
>>

  POP stack
  LET type = TYPEOF(DEREF(stack))
  IF ((type <= SIGLONGWORD_DATA) AND (type >= 0))
    RETURN TEXTLINE(types, type)
  ENDIF
  RETURN "unknown"

ENDLOCAL


LOCAL sub_tp
  VAR msg TEXT varn TEXT
  LET msg = #getdatatype
  POP varn
  CONCAT output, (varn+" is of type "+msg+"\n")
ENDLOCAL


VAR charV CHAR, byteV BYTE, wordV WORD, longwordV LONGWORD
VAR sigqwordV SIGQWORD, textV TEXT, fileV FILE, refV VARREF, noneV NONE
VAR singleV SINGLE, doubleV DOUBLE, extendedV EXTENDED, compV COMP
VAR sigbyteV SIGBYTE, sigwordV SIGWORD, siglongwordV SIGLONGWORD


call sub_tp, 'charV', @charV
call sub_tp, 'byteV', @byteV
call sub_tp, 'wordV', @wordV
call sub_tp, 'longwordV', @longwordV

call sub_tp, 'sigqwordV', @sigqwordV
call sub_tp, 'textV', @textV
call sub_tp, 'fileV', @fileV
call sub_tp, 'refV', @refV
call sub_tp, 'noneV', @noneV

call sub_tp, 'singleV', @singleV
call sub_tp, 'doubleV', @doubleV
call sub_tp, 'compV', @compV
call sub_tp, 'extendedV', @extendedV

call sub_tp, 'sigbyteV', @sigbyteV
call sub_tp, 'sigwordV', @sigwordV
call sub_tp, 'siglongwordV', @siglongwordV

TEXTBOX output

top bottom
DOUBLE DOUBLE(expr)
Parameters:

expr: an expression

more...

less...

The DOUBLE() function is used to convert the expression expr to the DOUBLE precision floating point data type.

If expr is a numeric or CHAR expression, its numeric value is returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a floating point number. If conversion fails, an error is raised.
See also: Data types.
Sample:
VAR inp TEXT si SINGLE do DOUBLE ex EXTENDED

REPEAT
  inp = INPUT('Enter a floating point value')
UNTIL ISFLOAT(inp)

LET si = SINGLE(inp)
LET do = DOUBLE(inp)
LET ex = EXTENDED(inp)

MSGBOX ('The number you entered was (single precision): '+TEXT(si))
MSGBOX ('The number you entered was (double precision): '+TEXT(do))
MSGBOX ('The number you entered was (extended precision): '+TEXT(ex))

top bottom
TEXT ENVPARSE(string)
Parameters:

string: an expression of type TEXT

more...

less...

The ENVPARSE() function expands all environment variables in string to their actual values. Environment variables must be enclosed in percent signs (%).

Three special variables do exist:
Sample:
= show current date and time
MSGBOX (ENVPARSE('Current Date: %date%, Current Time: %time%'))

top bottom
TEXT ESCAPEHTML(string [, isunicode [, leaveblanks]])*
Parameters:

string: an expression of type TEXT
isunicode: optional expression of type BYTE
leaveblanks: optional expression of type BYTE

more...

less...

The ESCAPEHTML() function escapes all characters in string that have a special meaning/are not printeable in HTML. This function might be useful when printing characters like "<", ">" and so on to the structure viewer in raw mode.

If the optional parameter isunicode is set to 1, the text in string is treated as Unicode Little Endian text.
If the optional parameter leaveblanks is set to 1, blanks (0x20 chars) are not escaped to '&nbsp;', so they can lead to line breaks in the html document.
Sample:
INCLUDE 'def.mps'
= make some special characters html friendly
VAR s TEXT
s = ESCAPEHTML("<> &⌐")
= s now contains "&lt;&gt;&nbsp;&amp;&copy;"
MSGBOX s

= leave the blank unescaped
s = ESCAPEHTML("<> &⌐", 0, 1)
= s now contains "&lt;&gt; &amp;&copy;"
MSGBOX s


= now try the unicode version of the euro sign
VAR w TEXT
w = TEXTCONVERT("€", TEXTCONVERT_ANSI, TEXTCONVERT_UNICODE)
w = ESCAPEHTML(w, 1)
= w now contains "&euro;"
MSGBOX w

top bottom
EXTENDED EXP(x)*
Parameters:

x: a floating point expression

more...

less...

EXP() returns the constant e raised to the power x.

top bottom
EXTENDED EXTENDED(expr)
Parameters:

expr: an expression

more...

less...

The EXTENDED() function is used to convert the expression expr to the EXTENDED precision floating point data type.

If expr is a numeric or CHAR expression, its numeric value is returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a floating point number. If conversion fails, an error is raised.
See also: Data types.
Sample:
VAR inp TEXT si SINGLE do DOUBLE ex EXTENDED

REPEAT
  inp = INPUT('Enter a floating point value')
UNTIL ISFLOAT(inp)

LET si = SINGLE(inp)
LET do = DOUBLE(inp)
LET ex = EXTENDED(inp)

MSGBOX ('The number you entered was (single precision): '+TEXT(si))
MSGBOX ('The number you entered was (double precision): '+TEXT(do))
MSGBOX ('The number you entered was (extended precision): '+TEXT(ex))

top bottom
TEXT EXTRACTNAME(name)
Parameters:

name: an expression of type TEXT

more...

less...

The EXTRACTNAME() function returns the filename part of name without the preceding path.
See also: EXTRACTPATH().
Sample:
VAR fname TEXT, fpath TEXT

LET fname = ASKOPENFILENAME('Select a file')
LET fpath = EXTRACTPATH(fname)
LET fname = EXTRACTNAME(fname)

MSGBOX ('The file '+fname+' is in directory '+fpath)

top bottom
TEXT EXTRACTPATH(name)
Parameters:

name: an expression of type TEXT

more...

less...

The EXTRACTPATH() function returns the path part of name including the trailing backslash.
See also: EXTRACTNAME().
Sample:
VAR fname TEXT, fpath TEXT

LET fname = ASKOPENFILENAME('Select a file')
LET fpath = EXTRACTPATH(fname)
LET fname = EXTRACTNAME(fname)

MSGBOX ('The file '+fname+' is in directory '+fpath)

top bottom
BYTE FILEEXISTS(filename)
Parameters:

filename: an expression of type TEXT

more...

less...

The FILEEXISTS() function returns 1 if the file filename exists, otherwise 0 is returned.
Sample:
VAR fname TEXT

LET fname = INPUT('Enter a filename to open in Tiny Hexer')

IF FILEEXISTS(fname)
  !CMD.FileOpen fname
ELSE
  ERROR ('File '+fname+' not found')
ENDIF

top bottom
VALUE FILEGETPROP(file, property)
Parameters:

file: a variable of type FILE
property: an expression of type TEXT

more...

less...

FILEGETPROP() is used to retrieve a property of a special file.

The data type of the returned value depends on the property.


List of available properties

See also: FILESETPROP command, FILEOPEN().
Sample:
VAR ed FILE, val BYTE

= open the current editor window
LET ed = FILEOPEN('::current', 'r')

= get bytes per row
LET val = FILEGETPROP(ed, 'BytesPerRow')

= close the file
FILECLOSE ed

= show the BytesPerRow property
MSGBOX ('Current editor displays '+DEC(val)+' Bytes per row')

top bottom
FILE FILEOPEN(filename, mode)
Parameters:

filename, mode: expressions of type TEXT

more...

less...

Use FILEOPEN() to attach file filename to a FILE type variable.

The mode parameter tells Tiny Hexer Script how to open the file and what access to grant to the file's contents. This parameter must be a combination of one or more of the following characters:
Special Files:
In Tiny Hexer there are numerous special files. To distinguish special files from ordinary files, the filename parameter must be start with a double colon "::". The following special files exist in Tiny Hexer:
See also: FILECLOSE command, FILEREAD(), FILEWRITE().
Sample:
= sample: read a file from disk and write its contents to a new
= editor window, xoring each byte by 255
VAR ed FILE, f FILE, b BYTE sz LONGWORD lp LONGWORD

= open the file on disk (readonly "r")
LET f = FILEOPEN(ASKOPENFILENAME('Select a file'), 'r')

= open a new editor window
LET ed = FILEOPEN('::new', 'c')

LET sz = FILESIZE(f)
LET lp = 0

= set datasize of editor to file's size
FILESETPROP ed, 'Size', sz
= Changing the size sets the file pointer to eof, so reset
FILESEEK ed, 0

= read and transform the file's contents and write the data to the editor
WHILE FILEREAD(f, @b)
  SHOWPROGRESS sz, lp
  INC lp, 1
  LET b = b XOR 255
  FILEWRITE ed, b
ENDWHILE

= close the file handles
FILECLOSE ed
FILECLOSE f

top bottom
LONGWORD FILEPOS(file)
Parameters:

file: file type variable

more...

less...

The FILEPOS() returns the current position pointer of file.
See also: FILESEEK command, FILEREAD(), FILESIZE(), FILEWRITE().
Sample:
INCLUDE 'def.mps'

VAR Position LONGWORD mpth FILE


= open tiny hexer itself in a new editor window
!CMD.FileOpen ENVPARSE('%apppath%\mpth.exe')

= attach a file to the editor, only read access is needed
mpth=FILEOPEN('::current', 'r')

Position=FILEPOS(mpth)

= show start position (0)
MSGBOX ("Position at start of file (= 0): "+DEC(Position)), (MB_OK OR MB_ICONINFORMATION)

= seek to file end
FILESEEK mpth, 0, FILE_END
= set cursor to end of file
!CMD.EditGoto '>0'

Position=FILEPOS(mpth)

= show end position (0)
MSGBOX ("Position at end of file (= file size): "+DEC(Position)), (MB_OK OR MB_ICONINFORMATION)


top bottom
LONGWORD FILEREAD(file, buffer [, count])
Parameters:

file: a variable of type FILE
buffer: an expression of type VARREF
count: an optional expression of type LONGWORD

more...

less...

Use the FILEREAD() function to read data from the file file into the variable referenced by buffer.

The optional count parameter tells Tiny Hexer Script how many bytes of data are to be read. If this parameter is omitted, the type of the variable referenced by buffer defines the amount of data to be read (BYTE, CHAR: 1 Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8 Bytes, TEXT: reads from the file until EOF or a 0x00 byte is found).

FILEREAD() returns the actual amount of data (in Bytes) that was read from the file.
See also: FILEREAD command, FILEWRITE().
Sample:
VAR f FILE, wholefile TEXT, amount LONGWORD

= open the file c:\boot.ini for reading
LET f = FILEOPEN('c:\boot.ini', 'r')

= read up to 500000 bytes from the file
amount=FILEREAD(f, @wholefile, 500000)

= close the file handle
FILECLOSE f

= tell how many data has been read
MSGBOX ("Bytes read: "+DEC(amount))

top bottom
LONGWORD FILEREADBE(file, buffer)
Parameters:

file: a variable of type FILE
buffer: an expression of type VARREF

more...

less...

Use the FILEREADBE() function to read data from the file file into the variable referenced by buffer if the file's contents are stored in BIG ENDIAN format (e.g. on Motorola CPUs).

The type of the variable referenced by buffer defines the amount of data to be read (BYTE, CHAR: 1 Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8 Bytes, TEXT: reads from the file until EOF or a 0x00 byte is found).

If the variable referenced by buffer is of type WORD, LONGWORD or SIGQWORD, the data is swapped after reading (e.g. LONGWORD = Byte 0 becomes Byte 3, Byte 1 becomes Byte 2, Byte 2 becomes Byte 1 and Byte 3 becomes Byte 0). On other data types, the function is similar to the FILEREAD() function (except for the missing count parameter).

FILEREADBE() returns the actual amount of data (in Bytes) that was read from the file.
See also: FILEREADBE command, FILEWRITEBE(), FILEREAD().

top bottom
TEXT FILES(index)*
Parameters:

index: expression of type LONGWORD

more...

less...

The FILES() function returns the filename of the editor child #index (first file is at index 0). Use the FILE_COUNT special variable to get the number of files currently opened in Tiny Hexer.
See also: FILE_COUNT special variable.
Sample:
= enumerate all open editor files

VAR d LONGWORD
VAR ed TEXT

d=FILE_COUNT
IF d == 0
  MSGBOX "No files open"
ELSE
  LOOP enum d
ENDIF
END

@@enum
ed=FILES(loop)
MSGBOX ("File "+DEC(loop+1)+": "+ed)
RETURN

top bottom
LONGWORD FILESIZE(file)
Parameters:

file: file type variable

more...

less...

The FILESIZE() returns the size (in Bytes) of file.
See also: FILESEEK command, FILEPOS().
Sample:
INCLUDE 'def.mps'

VAR Size LONGWORD mpth FILE


= open tiny hexer itself in a new editor window
!CMD.FileOpen ENVPARSE('%apppath%\mpth.exe')

= attach a file to the editor, only read access is needed
mpth=FILEOPEN('::current', 'r')

Size=FILESIZE(mpth)

MSGBOX ("Size of file: "+DEC(Size)), (MB_OK OR MB_ICONINFORMATION)

top bottom
LONGWORD FILEWRITE(file, data)
Parameters:

file: a variable of type FILE
data: an expression of type TEXT, CHAR, BYTE, WORD, LONGWORD or SIGQWORD

more...

less...

Use the FILEWRITE() function to write the contents of data to the file file.

The type of the data expression defines the amount of data to be written to the file (BYTE, CHAR: 1 Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8 Bytes, TEXT: length of the text value).

FILEWRITE() returns the actual amount of data (in Bytes) that has been written.
See also: FILEWRITE command, FILEREAD().
Sample:
INCLUDE 'def.mps'

VAR f FILE, dw LONGWORD, written LONGWORD, fname TEXT l TEXT
LET fname = 'c:\test.dat'

= enter a number
REPEAT
  l = INPUT('Enter a number')
UNTIL ISNUMBER(l)
LET dw=LONGWORD(l)

= create the file
LET f = FILEOPEN(fname, 'c')

= write the number in binary format
LET written=FILEWRITE(f, dw)

= close the file handle
FILECLOSE f

= check if all data has been written
IF written != LONGWORD_SIZE
  ERROR "Not all data could be written!"
ENDIF

top bottom
LONGWORD FILEWRITEBE(file, data)
Parameters:

file: a variable of type FILE
data: an expression of type TEXT, CHAR, BYTE, WORD, LONGWORD or SIGQWORD

more...

less...

Use the FILEWRITEBE() function to write the contents of data to the file file if the file's contents should be stored in BIG ENDIAN format (e.g. on Motorola CPUs).

The type of the data expression defines the amount of data to be written to the file (BYTE, CHAR: 1 Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8 Bytes, TEXT: length of the text value).

If data is of type WORD, LONGWORD or SIGQWORD, the data is swapped before writing (e.g. LONGWORD = Byte 0 becomes Byte 3, Byte 1 becomes Byte 2, Byte 2 becomes Byte 1 and Byte 3 becomes Byte 0). On other data types, the function is similar to the FILEWRITE() function.

FILEWRITEBE() returns the actual amount of data (in Bytes) that has been written.
See also: FILEWRITEBE command, FILEREADBE(), FILEWRITE().

top bottom
SIGLONGWORD FLOATTOIBM4(float)*
Parameters:

float: a floating point expression

more...

less...

FLOATTOIBM4() converts the value of float into the ibm single precision floating point format. You cannot use the resulting SIGLONGWORD value for calculation but to store floating point values in ibm format in a file.
See also: FLOATTOIBM8(), IBM4TOFLOAT().
Sample:
VAR e EXTENDED

VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values

LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)

LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)

top bottom
SIGQWORD FLOATTOIBM8(float)*
Parameters:

float: a floating point expression

more...

less...

FLOATTOIBM8() converts the value of float into the ibm double precision floating point format. You cannot use the resulting SIGQWORD value for calculation but to store floating point values in ibm format in a file.
See also: FLOATTOIBM4(), IBM8TOFLOAT().
Sample:
VAR e EXTENDED

VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values

LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)

LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)

top bottom
SIGLONGWORD FLOOR(number)*
Parameters:

number: a numeric expression

more...

less...

FLOOR() returns the ordinal value of the argument number, rounded towards -infinity.
See also: CEIL(), FRAC(), INT(), ROUND(), TRUNC().
Sample:
MSGBOX (DEC(FLOOR(2.0))):= results in "2"
MSGBOX (DEC(FLOOR(2.9999))):= results in "2"
MSGBOX (DEC(FLOOR(-2.9999))):= results in "-3"

top bottom
EXTENDED FRAC(number)*
Parameters:

number: a numeric expression

more...

less...

FRAC() returns the signed fractional part of the floating point value of number.
See also: CEIL(), FLOOR(), INT(), ROUND(), TRUNC().
Sample:
MSGBOX (TEXT(FRAC(2))):= results in "0"
MSGBOX (TEXT(FRAC(2.9999))):= results in "0.9999"
MSGBOX (TEXT(FRAC(-2.9999))):= results in "-0.9999"

top bottom
GUI functions for user defined dialogs
GUI functions are described on a separate page

top bottom
TEXT HEX(number [, usetype])
Parameters:

number: an ordinal expression
usetype: an optional expression of type BYTE

more...

less...

Use the HEX() function to convert the ordinal numeric expression number to a hexadecimal representation consisting of the characters "0".."9" and "A".."F". If the optional parameter usetype is set to 0, numbers < 0 are always converted as 64 bits signed values. If set to 1, the type of number is used to convert negative values. This flag affects the converted representation of negative values only, positive values are always calculated using the original data type.
See also: BIN(), DEC(), OCT().
Sample:
MSGBOX (HEX(BYTE(1))):= shows "01" (8 bits)
MSGBOX (HEX(WORD(256))):= shows "0100" (16 bits)
MSGBOX (HEX(LONGWORD(256))):= shows "00000100" (32 bits)
MSGBOX (HEX(SIGBYTE(-1))):= shows "FFFFFFFFFFFFFFFF" (64 bits)
MSGBOX (HEX(SIGBYTE(-1),1)):= shows "FF" (8 bits)
MSGBOX (HEX(SIGWORD(-1),1)):= shows "FFFF" (16 bits)

top bottom
TEXT HEX2BIN(strhex [, swaphalfbytes])
Parameters:

strhex: an expression of type TEXT
swaphalfbytes: an optional expression of type BYTE

more...

less...

The HEX2BIN() function is used to convert a hexadecimal data representation in strhex to binary data. Characters in strhex that are no hexadecimal digits are skipped.

If the optional paramater swaphalfbytes is set to 1, the order of the hexadecimal digits is <low halfbyte><high halfbyte>..., otherwise the order is <high halfbyte><low halfbyte>...
See also: BIN2HEX().
Sample:
= convert hexadecimal digits to data
VAR txt1 TEXT txt2 TEXT

txt1 = '42 43 45'

LET txt2 = HEX2BIN(txt1)
= txt2 now contains 'BCE'

MSGBOX txt2

LET txt2 = HEX2BIN(txt1, 1)
= txt2 now contains '$4T'

MSGBOX txt2

top bottom
SIGQWORD HEX2NUM(digits)
Parameters:

digits: an expression of type TEXT

more...

less...

The HEX2NUM() function is used to convert the TEXT expression digits (consisting of hexadecimal digits) to a number.
See also: ISHEX().
Sample:
VAR i SIGQWORD

LET i=HEX2NUM('FCE2')

= i is 64738 now
MSGBOX DEC(i)

top bottom
EXTENDED IBM4TOFLOAT(ibm4val)*
Parameters:

ibm4val: a SIGLONGWORD

more...

less...

IBM4TOFLOAT() converts the value of the ibm single precision float format value stored in the ibm4val pseudo SIGLONGWORD into an extended IEEE floating point value.
See also: FLOATTOIBM4(), IBM8TOFLOAT().
Sample:
VAR e EXTENDED

VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values

LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)

LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)

top bottom
EXTENDED IBM8TOFLOAT(ibm8val)*
Parameters:

ibm8val: a SIGQWORD

more...

less...

IBM8TOFLOAT() converts the value of the ibm double precision float format value stored in the ibm4val pseudo SIGQWORD into an extended IEEE floating point value.
See also: FLOATTOIBM8(), IBM4TOFLOAT().
Sample:
VAR e EXTENDED

VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values

LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)

LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)

top bottom
BYTE INIREAD(filename, section, key, buffer)
Parameters:

filename, section, key: expressions of type TEXT
buffer: VARREF

more...

less...

Use the INIREAD() function to read values from ini-style text files.

filename is the name of the ini file.
section is the name of the section in the ini file ([section] lines).
key is the name of the key in the ini file (the part to the left of the equal sign).
buffer is a reference to a variable that will contain the value read from the ini file.

If the specified key could be read from the ini file, 1 is returned. Otherwise 0 is returned.
See also: INIWRITE command, REGREAD() function.
Sample:
DEF ini "d:\\mpthtest.ini"

= write some data to the ini file
iniwrite ini, "section1", "key1", 2
iniwrite ini, "section2", "key2", "abc"

VAR val LONGWORD val_t TEXT

= try to read section1/key1 as longword
IF INIREAD(ini, "section1", "key1", @val)
  MSGBOX ('Value of section1/key1: '+DEC(val))
ELSE
  ERROR ('Cannot read section1/key1 value from '+ini)
ENDIF

= try to read section2/key2 as text
IF INIREAD(ini, "section2", "key2", @val_t)
  MSGBOX ('Value of section2/key2: '+val_t)
ELSE
  ERROR ('Cannot read section2/key2 value from '+ini)
ENDIF

top bottom
TEXT INPUT(prompt)
TEXT INPUT(caption, prompt [,default])*
Parameters:

caption, prompt, default: expressions of type TEXT

more...

less...

The INPUT() function is used to bring up an input dialog box ready for the user to enter a TEXT string in its edit box. INPUT() returns the value entered by the user.

caption is the title of the dialog box. If omitted, a default is used.

prompt is the text that prompts the user to enter a string in the edit box.

default is the string that appears in the edit box when the dialog box is displayed. If omitted, the edit box is empty.

Note: If the user chooses the "Cancel" button in the input dialog, the script will be terminated if no error handler is set.
See also: INPUTNUMBER().
Sample:
VAR forename TEXT, surname TEXT

LET forename=INPUT('Please enter your first name')
LET surname=INPUT('Surname', 'Please enter your last name')

MSGBOX ("Hello, "+forename+' '+surname+'!')

top bottom
SIGQWORD INPUTNUMBER(prompt)
SIGQWORD INPUTNUMBER(caption, prompt [,default])*
Parameters:

caption, prompt: expressions of type TEXT
default: an expression of type SIGQWORD

more...

less...

The INPUTNUMBER() function is used to bring up a numeric input dialog box ready for the user to enter an ordinal (integral) number in its edit box in binary, octal, decimal or hexadecimal format. INPUTNUMBER() returns the value entered by the user. The edit box has an additional button to bring up a popup calculator.

caption is the title of the dialog box. If omitted, a default is used.

prompt is the text that prompts the user to enter a string in the edit box.

default is the number that appears in the edit box when the dialog box is displayed. If omitted, the edit box is set to zero.

Note: If the user chooses the "Cancel" button in the numeric input dialog, the script will be terminated if no error handler is set.
See also: INPUT().
Sample:
VAR addend1 SIGQWORD, addend2 SIGQWORD

LET addend1=INPUTNUMBER('Addition','Please enter addend 1')
LET addend2=INPUTNUMBER('Addition','Please enter addend 2')

MSGBOX ("The sum of "+DEC(addend1)+" and "+DEC(addend2)+" is "+DEC(addend1+addend2))

top bottom
EXTENDED INT(number)*
Parameters:

number: a numeric expression

more...

less...

INT() returns the signed integral part of the floating point value of number, that is the fractional part is stripped off.
See also: CEIL(), FLOOR(), FRAC(), ROUND(), TRUNC().
Sample:
MSGBOX (TEXT(INT(2.005))):= results in "2"
MSGBOX (TEXT(INT(2.9999))):= results in "2"
MSGBOX (TEXT(INT(-2.9999))):= results in "-2"

top bottom
BYTE ISFLOAT(value)
Parameters:

value: an expression of type TEXT

more...

less...

Use the ISFLOAT() function to determine whether the TEXT value is a valid floating point number representation (that is value solely consists of decimal digits and optionally decimal comma, minus sign and exponential sign ("E"). If value is a valid floating point number, 1 is returned, otherwise 0 is returned.
See also: ISNUMBER().
Sample:
VAR inp TEXT

REPEAT
  inp=INPUT('Enter a floating point value')
  IF not ISFLOAT(inp)
    MSGBOX (inp+" is not a valid floating point number!")
  ENDIF
UNTIL ISFLOAT(inp)
MSGBOX (INP+" = "+TEXT(EXTENDED(INP)))

top bottom
BYTE ISHEX(value)
Parameters:

value: an expression of type TEXT

more...

less...

Use the ISHEX() function to determine whether the TEXT value is a valid hexadecimal number (that is value solely consists of hexadecimal digits, it may optionally be prefixed by "0x"), max. 64 bits. If value is a valid hexadecimal number, 1 is returned, otherwise 0 is returned.
See also: HEX2NUM(), ISNUMBER().
Sample:
VAR inp TEXT

REPEAT
  inp=INPUT('Enter a hexadecimal value')
  IF not ISHEX(inp)
    MSGBOX (inp+" is not a valid hexadecimal number!")
  ENDIF
UNTIL ISHEX(inp)

top bottom
BYTE ISNUMBER(value)
Parameters:

value: an expression of type TEXT

more...

less...

Use the ISNUMBER() function to determine whether the TEXT value is a valid ordinal numeric representation either in decimal (e.g. '100'), hexadecimal (e.g. '0xff') or octal (e.g. '755o') notation (max. 64 bits wide). If value is a valid number, 1 is returned, otherwise 0 is returned.
See also: ISFLOAT(), ISHEX().
Sample:
VAR inp TEXT

REPEAT
  inp=INPUT('Enter a number')
  IF not ISNUMBER(inp)
    MSGBOX (inp+" is not a number!")
  ENDIF
UNTIL ISNUMBER(inp)

top bottom
EXTENDED LOG10(x)*
Parameters:

x: a floating point expression

more...

less...

LOG10() returns the base 10 logarithm of x.

top bottom
EXTENDED LOGN(x)*
Parameters:

x: a floating point expression

more...

less...

LOGN() returns the natural logarithm of x.

top bottom
LONGWORD LONGWORD(expr)
Parameters:

expr: an expression

more...

less...

The LONGWORD() function is used to convert the expression expr to the LONGWORD data type.

If expr is a numeric or CHAR expression, the lowest 32 bits of its ordinal value are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest 32 bits of the converted number are returned.

In earlier versions of Tiny Hexer, this function was called DWORD(). This alias is deprecated.
See also: Data types.
Sample:
= convert a text to a longword number
VAR inp TEXT dw LONGWORD

REPEAT
  inp = INPUT('Enter a numeric value')
UNTIL ISNUMBER(inp)

LET dw = LONGWORD(inp)

= output hexadecimal
MSGBOX ('The number you entered was (hex): '+HEX(dw))

top bottom
SIGQWORD MAX(i1, i2)*
EXTENDED MAX(f1, f2)*
Parameters:

i1, i2: ordinal numeric expressions
f1, f2: floating point numeric expressions

more...

less...

The MAX() function returns the greater of the two parameters i1 and i2 or f1 and f2, respectively.
See also: MIN().
Sample:
MSGBOX DEC(MAX(1,2)):= results in "2"
MSGBOX TEXT(MAX(1.5,2.5)):= results in "2.5"

top bottom
SIGQWORD MIN(i1, i2)*
EXTENDED MIN(f1, f2)*
Parameters:

i1, i2: ordinal numeric expressions
f1, f2: floating point numeric expressions

more...

less...

The MIN() function returns the lesser of the two parameters i1 and i2 or f1 and f2, respectively.
See also: MAX().
Sample:
MSGBOX DEC(MIN(1,2)):= results in "1"
MSGBOX TEXT(MIN(1.5,2.5)):= results in "1.5"

top bottom
LONGWORD MSGBOX(message [, flags [, title]])
Parameters:

message: expression of type TEXT
flags: optional expression of type LONGWORD
title: optional expression of type TEXT

more...

less...

MSGBOX() opens a dialog displaying the text message.

The optional flags parameter tells Windows to change the behaviour and/or appearance of the dialog (see MSGBOX flags).

MSGBOX() returns the value of the button the user has selected:

The optional title parameter modifies the title bar caption of the message dialog.
See also: MSGBOX command.
Sample:
INCLUDE 'def.mps'

VAR btn BYTE

btn=MSGBOX('Click a button', MB_CANCELTRYCONTINUE OR MB_ICONASTERISK)

IF btn==IDCANCEL
  MSGBOX "'Cancel' button has been selected"
ELSE
  IF btn==IDCONTINUE
    MSGBOX "'Continue' button has been selected"
  ELSE
    MSGBOX "'Retry' button has been selected"
  ENDIF
ENDIF

top bottom
TEXT OCT(number [, usetype])
Parameters:

number: an ordinal expression
usetype: an optional expression of type BYTE

more...

less...

Use the OCT() function to convert the ordinal numeric expression number to a octal representation consisting of the characters "0".."7". If the optional parameter usetype is set to 0, numbers < 0 are always converted as 64 bits signed values. If set to 1, the type of number is used to convert negative values. This flag affects the converted representation of negative values only, positive values are always calculated to the shortest possible length.
See also: BIN(), DEC(), HEX().
Sample:
MSGBOX (OCT(BYTE(1))):= shows "1" (8 bits)
MSGBOX (OCT(WORD(256))):= shows "400" (16 bits)
MSGBOX (OCT(LONGWORD(256))):= shows "400" (32 bits, but msbs set to 0)
MSGBOX (OCT(SIGBYTE(-1))):= shows "1777777777777777777777" (64 bits)
MSGBOX (OCT(SIGBYTE(-1),1)):= shows "377" (8 bits)
MSGBOX (OCT(SIGWORD(-1),1)):= shows "177777" (16 bits)

top bottom
BYTE ODD(x)*
Parameters:

x: an ordinal numerical expression

more...

less...

ODD() returns 1 if the value of x is odd, 0 if it's even or 0.

top bottom
TEXT PARAMS(index)
Parameters:

index: expression of type LONGWORD

more...

less...

The PARAMS() function returns the contents of the parameter #index (first parameter is at index 0) passed to the script when it's started by a tools menu item.
See also: PARAM_COUNT special variable.
Sample:
= save this script under c:\script1.mps
= start of script 1

= execute script 2 and pass two parameters to it
= parameters are separated by blanks or comma
= multiple parameters enclosed in double quotes are used as single parameters
!CMD.ToolsExecuteScript "c:\\script2.mps", '"First argument", "Second argument"'

END

= end of script 1

= save this script under c:\script2.mps
= start of script 2

VAR lp LONGWORD, param TEXT

= show all parameters
lp=0
WHILE lp < PARAM_COUNT
  param=PARAMS(lp)
  MSGBOX ("Parameter "+DEC(lp+1)+": "+param)
  INC lp, 1
ENDWHILE

END

= end of script 2


top bottom
SIGQWORD POSITIONS(index)*
Parameters:

index: expression of type SIGQWORD

more...

less...

The POSITIONS() function returns the value of the entry #index in the position list (first entry is at index 0, an index value of -1 returns the value of the entry that has the focus.)
See also: POSITION_COUNT special variable, POSITION_ADD(), POSITION_SELECTED().
Sample:
= show the value of the currently focused entry in the position list
VAR val SIGQWORD

val=POSITIONS(-1)

IF (val == -1)
  ERROR "No entry selected in the position list"
ELSE
  MSGBOX ("Value of the focused entry in the position list: "+TEXT(LONGWORD(val)))
ENDIF

top bottom
LONGWORD POSITION_ADD(value [, length])*
Parameters:

value, length: expressions of type SIGQWORD

more...

less...

The POSITION_ADD() function is used to add a position value to the position list. The optional parameter length is used to add a selection length. The function returns the index of the new entry in the position list.
See also: POSITION_COUNT special variable, POSITIONS(), POSITION_SELECTED().
Sample:
= add an entry to the position list and select it
VAR index LONGWORD, wasselected BYTE, newpos LONGWORD

= query a value to be added to the position list
newpos=INPUTNUMBER("Enter a position value to be added to the position list")

IF (newpos == 0):END:ENDIF

index=POSITION_ADD(newpos)

= select and focus the newly added item
wasselected = POSITION_SELECTED(index, 1, 1)


top bottom
BYTE POSITION_SELECTED(index [, doselect [, dosetfocus]])*
Parameters:

index: an expression of type SIGQWORD
doselect, dosetfocus: optional expressions of type BYTE

more...

less...

The POSITION_SELECTED() function is used to tell whether entry #index of the position list is currently selected. The function returns 1 if the entry is selected and 0 otherwise (the first entry is at index 0, an index value of -1 acts on the entry that has the focus.)

The optional doselect parameter can be used to change the entry's selection state (1 selects the item, 0 deselects it).

The optional dosetfocus parameter, when set to 1, makes that entry the focused entry in the position list.
See also: POSITION_COUNT special variable, POSITIONS(), POSITION_ADD().
Sample:
= add an entry to the position list and select it
VAR newpos SIGQWORD, index LONGWORD, wasselected BYTE

= query a value to be added to the position list
newpos=SIGQWORD(INPUT("", "Enter a position value to be added to the position list","-1"))

IF (newpos < 0):END:ENDIF

index=POSITION_ADD(newpos)

= select and focus the newly added position
wasselected = POSITION_SELECTED(index, 1, 1)


top bottom
LONGWORD RANDOM(max)
Parameters:

max: an expression of type LONGWORD

more...

less...

The RANDOM() function returns an ordinal random number within the range 0..max-1.
See also: FRANDOM and QRANDOM special variables.
Sample:
MSGBOX "Guess a number game", 64

VAR number BYTE, entered BYTE

LABEL start

= randomly choose a number between 1 and 10
LET number = RANDOM(10)+1

LABEL loop

LET entered = BYTE(INPUTNUMBER('Enter a number between 1 and 10'))
IF entered == number
  MSGBOX 'Right!'
ELSE
  IF number < entered
    MSGBOX ('My number is less than '+DEC(entered))
  ELSE
    MSGBOX ('My number is greater than '+DEC(entered))
  ENDIF
  GOTO loop
ENDIF

GOTO start

top bottom
BYTE REGREAD(key, name, buffer)
Parameters:

key, name: expressions of type TEXT
buffer: VARREF

more...

less...

Use the REGREAD() function to read values from the registry.

key is the name of the registry key. by default, REGREAD() reads values from the HKEY_CURRENT_USER root key. to select another root key, prefix key by the name of the root key (e.g. 'HKEY_LOCAL_MACHINE\Software...').

Note: To read data from Tiny Hexer's settings database rather than from the registry, use the 'HKEY_SETTINGS' pseudo root key.

name is the name of the value in the given registry key.
buffer is a reference to a variable that will contain the value read from the registry.

If the specified value could be read from the registry, 1 is returned, otherwise 0 is returned.
See also: REGWRITE command, INIREAD() function.
Sample:
DEF reg "HKEY_CURRENT_USER\\Temporary Test Key"

= write some data to the registry
regwrite reg, "name1", 2
regwrite reg, "name2", "abc"

VAR val LONGWORD val_t TEXT

= try to read name1 as longword
IF REGREAD(reg, "name1", @val)
  MSGBOX ('Value of name1: '+TEXT(val))
ELSE
  ERROR ('Cannot read name1 value from '+reg)
ENDIF

= try to read name2 as text
IF REGREAD(reg, "name2", @val_t)
  MSGBOX ('Value of name2: '+val_t)
ELSE
  ERROR ('Cannot read name2 value from '+reg)
ENDIF

= delete temporary key
regwrite reg

top bottom
SIGQWORD ROUND(number)*
Parameters:

number: a numeric expression

more...

less...

ROUND() returns the ordinal value of the argument number, rounded to the nearest ordinal number.
See also: CEIL(), FLOOR(), FRAC(), INT(), TRUNC().
Sample:
MSGBOX (DEC(ROUND(2.499))):= results in "2"
MSGBOX (DEC(ROUND(2.501))):= results in "3"
MSGBOX (DEC(ROUND(-2.499))):= results in "-2"
MSGBOX (DEC(ROUND(-2.501))):= results in "-3"

top bottom
TEXT SELECTEDITORFILE(title, prompt [, files [, multiselect [, default]]]) *
Parameters:

title, prompt, files (optional): expressions of type TEXT
multiselect: an optional expression of type BYTE
default: an optional expression of type SIGQWORD

more...

less...

The SELECTEDITORFILE() function pops up a dialog that allows you to select currently opened editor files from a list. SELECTEDITORFILE() returns the name (or newline sparated list of names) that has been selected in the dialog.

title is the caption of the dialog, prompt is displayed as a hint label in the dialog.

If the optional files parameter is used and contains file names (separated by newline characters), the dialog only shows these filenames, otherwise all files currently opened are displayed.

If the optional multiselect parameter is set to a value different from zero, the dialog allows to select multiple files (the function returns multiple file names separated by newline characters).

The optional default value is used to specify a preselection when the dialog is displayed: set it to -1 to select all files by default (only if multiselect is enabled), set it to 0 for no preselection or set it to a line index into the files lines "array" (1-based).
Sample:
= show overall size of selected files
VAR selected TEXT

= set decimal output
INCLUDE 'def.mps'

selected = SELECTEDITORFILE('Overall file size', 'Select some files:', '', 1, -1)

VAR amount LONGWORD size SIGQWORD index LONGWORD f FILE
= get the number of returned files
amount = TEXTLINECOUNT(selected)
IF (amount)
  size = 0: = reset size
  index = 0: = reset index
  WHILE (index < amount)
    = open file to get size, filenames are separated by newlines
    = so get the current line via TEXTLINE()
    f = FILEOPEN(('::'+TEXTLINE(selected, index)), 'r')

    INC index, 1

    = retrieve the size of the file and add to the overall size
    INC size, FILESIZE(f)

    FILECLOSE f
  ENDWHILE

  = show the overall size
  MSGBOX ("Number of files:"+DEC(amount)+"\nOverall file size: "+DEC(size)), MB_ICONINFORMATION
ENDIF

top bottom
LONGWORD SHELL(program [, parameters [, show [, directory [, output]]]])
Parameters:

program, parameters, directory: expressions of type TEXT
show: an expression of type LONGWORD
output: an expression of type VARREF

more...

less...

The SHELL() function is used to execute the external application program. Script execution is always stopped until program has finished. SHELL() returns the exit code of the program, if it cannot be executed, 0xFFFFFFFF is returned.

Optionally the command line arguments parameters can be passed to program.

Additionally you can tell Tiny Hexer Script to show or hide the external application using the show parameter (SW_HIDE, SW_SHOW...)

The optional directory parameter tells Windows to set program's current directory.

The optional output parameter is a reference to a TEXT variable that will contain the output of program after its execution.
See also: SHELL command.
Sample:
VAR exitcode LONGWORD num LONGWORD fname TEXT

num=INPUTNUMBER('Enter an exitcode')

VAR f FILE
= create a temp. batch file
fname=ENVPARSE('%temp%')+'\shelltest1.bat'
f=FILEOPEN(fname,'c')

FILEWRITE f, ('@echo Exiting with code '+DEC(num)+"\r\n")
FILEWRITE f, ('@exit '+DEC(num)+"\r\n")
FILECLOSE f

= run the created batch
exitcode=SHELL(fname)

FILEDELETE (fname)

= show the exitcode
MSGBOX ('Exitcode of '+fname+': '+DEC(exitcode)+" (wanted: "+DEC(num)+")")

top bottom
SIGBYTE SIGBYTE(expr)
Parameters:

expr: an expression

more...

less...

The SIGBYTE() function is used to convert the expression expr to the SIGBYTE data type. As SIGBYTE is a signed numeric data type, it can only store 7 bits of data though it is a 8 bits wide data type.

If expr is a numeric or CHAR expression, the lowest 7 bits of its ordinal value and its sign are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest 7 bits of the converted number and its sign are returned are returned.
See also: Data types.
Sample:
VAR inp TEXT

REPEAT
  REPEAT
    inp = INPUT('', 'Enter a negative integral number',  '-1')
  UNTIL ISNUMBER(inp)
UNTIL (SIGBYTE(inp) < 0)

top bottom
SIGLONGWORD SIGLONGWORD(expr)
Parameters:

expr: an expression

more...

less...

The SIGLONGWORD() function is used to convert the expression expr to the SIGLONGWORD data type. As SIGLONGWORD is a signed numeric data type, it can only store 31 bits of data though it is a 32 bits wide data type.

If expr is a numeric or CHAR expression, the lowest 31 bits of its ordinal value and its sign are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest 31 bits of the converted number and its sign are returned are returned.
See also: Data types.
Sample:
VAR inp TEXT

REPEAT
  REPEAT
    inp = INPUT('', 'Enter a negative integral number',  '-1')
  UNTIL ISNUMBER(inp)
UNTIL (SIGLONGWORD(inp) < 0)

top bottom
SIGQWORD SIGN(ivalue)*
EXTENDED SIGN(fvalue)*
Parameters:

ivalue: an ordinal numeric expression
fvalue: a floating point numeric expression

more...

less...

The SIGN() function returns the sign of the parameter ivalue or fvalue, respectively.
Sample:
MSGBOX DEC(SIGN(-5)):= results in "-1"
MSGBOX DEC(SIGN(-0)):= results in "0"
MSGBOX DEC(SIGN(5)):= results in "1"
MSGBOX TEXT(SIGN(-5.5)):= results in "-1"
MSGBOX TEXT(SIGN(-0.0)):= results in "0"
MSGBOX TEXT(SIGN(5.5)):= results in "1"

top bottom
SIGQWORD SIGQWORD(expr)
Parameters:

expr: an expression

more...

less...

The SIGQWORD() function is used to convert the expression expr to the SIGQWORD data type. As SIGQWORD is a signed numeric data type, it can only store 63 bits of data though it is a 64 bits wide data type.

If expr is a numeric or CHAR expression, the lowest 63 bits of its ordinal value and its sign are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest 63 bits of the converted number and its sign are returned are returned.

In earlier versions of Tiny Hexer, this function was called QWORD(). This alias is deprecated.
See also: Data types.
Sample:
VAR inp TEXT

REPEAT
  REPEAT
    inp = INPUT('', 'Enter a negative integral number',  '-1')
  UNTIL ISNUMBER(inp)
UNTIL (SIGQWORD(inp) < 0)

top bottom
SIGWORD SIGWORD(expr)
Parameters:

expr: an expression

more...

less...

The SIGWORD() function is used to convert the expression expr to the SIGWORD data type. As SIGWORD is a signed numeric data type, it can only store 15 bits of data though it is a 16 bits wide data type.

If expr is a numeric or CHAR expression, the lowest 15 bits of its ordinal value and its sign are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest 15 bits of the converted number and its sign are returned are returned.
See also: Data types.
Sample:
VAR inp TEXT

REPEAT
  REPEAT
    inp = INPUT('', 'Enter a negative integral number',  '-1')
  UNTIL ISNUMBER(inp)
UNTIL (SIGWORD(inp) < 0)

top bottom
EXTENDED SIN(number)*
Parameters:

number: a floating point expression

more...

less...

SIN() returns the sine of the argument number (radian).

top bottom
SINGLE SINGLE(expr)
Parameters:

expr: an expression

more...

less...

The SINGLE() function is used to convert the expression expr to the SINGLE precision floating point data type.

If expr is a numeric or CHAR expression, its numeric value is returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a floating point number. If conversion fails, an error is raised.
See also: Data types.
Sample:
VAR inp TEXT si SINGLE do DOUBLE ex EXTENDED

REPEAT
  inp = INPUT('Enter a floating point value')
UNTIL ISFLOAT(inp)

LET si = SINGLE(inp)
LET do = DOUBLE(inp)
LET ex = EXTENDED(inp)

MSGBOX ('The number you entered was (single precision): '+TEXT(si))
MSGBOX ('The number you entered was (double precision): '+TEXT(do))
MSGBOX ('The number you entered was (extended precision): '+TEXT(ex))

top bottom
EXTENDED SQRT(x)*
Parameters:

x: a floating point expression

more...

less...

SQRT() returns the square root of x.

top bottom
SIGQWORD TAG_LEN(ref)
Parameters:

ref: an expression of type VARREF

more...

less...

The TAG_LEN() function returns the length tag of the variable referenced by ref.

If the referenced variable is not tagged, -1 is returned.
See also: Variable tagging, COPYTAGS command, TAGVAR command, TAG_POS(), OPTION READTAGS directive.
Sample:
= enable variable tagging
OPTION READTAGS, 1

VAR f FILE, t TEXT, msg TEXT

= open tiny hexer itself
f=FILEOPEN(ENVPARSE('%apppath%\mpth.exe'),'r')

= locate a specific position
FILESEEK f, 986284

= read text from file with automatic tagging
FILEREAD f, t, 9
= t is now tagged with file position and data length

FILECLOSE f

msg='Data read from file: "'+t+'"'+"\n\r"
CONCAT msg, 'At position: '+DEC(TAG_POS(@t))+"\n\r"
CONCAT msg, 'Data length: '+DEC(TAG_LEN(@t))+"\n\r"

MSGBOX msg

top bottom
SIGQWORD TAG_POS(ref)
Parameters:

ref: an expression of type VARREF

more...

less...

The TAG_POS() function returns the position tag of the variable referenced by ref.

If the referenced variable is not tagged, -1 is returned.
See also: Variable tagging, COPYTAGS command, TAGVAR command, TAG_LEN(), OPTION READTAGS directive.
Sample:
= enable variable tagging
OPTION READTAGS, 1

VAR f FILE, t TEXT, msg TEXT

= open tiny hexer itself
f=FILEOPEN(ENVPARSE('%apppath%\mpth.exe'),'r')

= locate a specific position
FILESEEK f, 986284

= read text from file with automatic tagging
FILEREAD f, t, 9
= t is now tagged with file position and data length

FILECLOSE f

msg='Data read from file: "'+t+'"'+"\n\r"
CONCAT msg, 'At position: '+DEC(TAG_POS(@t))+"\n\r"
CONCAT msg, 'Data length: '+DEC(TAG_LEN(@t))+"\n\r"

MSGBOX msg

top bottom
EXTENDED TAN(number)*
Parameters:

number: a floating point expression

more...

less...

TAN() returns the tangent of the argument number (radian).

top bottom
TEXT TEXT(expr)
Parameters:

expr: an expression

more...

less...

The TEXT() function is used to convert the expression expr to the TEXT data type.

If expr is a numeric expression, its value is converted to a textual represention; the conversion format depends on the values of the NUMBER_RADIX, NUMBER_PREFIX and NUMBER_SUFFIX special variables if the number is ordinal, when converting floating point numbers, they are always converted using base (radix) 10.

If expr is of type TEXT or CHAR, a copy of the string is returned.
See also: BIN(), DEC(), HEX(), OCT(); Data types; NUMBER_RADIX, NUMBER_PREFIX and NUMBER_SUFFIX special variables.
Sample:
= show different number to text conversions
VAR number WORD txt TEXT

number=64738

= binary (radix 2)
NUMBER_RADIX=2
NUMBER_PREFIX='%'
NUMBER_SUFFIX=''

MSGBOX TEXT(number)

= octal (radix 8)
NUMBER_RADIX=8
NUMBER_PREFIX=''
NUMBER_SUFFIX='o'

MSGBOX TEXT(number)

= octal (radix 8), alternate output format
NUMBER_RADIX=8
NUMBER_PREFIX='0'
NUMBER_SUFFIX=''

MSGBOX TEXT(number)

= decimal (base 10)
NUMBER_RADIX=10
NUMBER_PREFIX=''
NUMBER_SUFFIX=''

MSGBOX TEXT(number)

= decimal (base 10), "alternate" format
NUMBER_RADIX=10
NUMBER_PREFIX='(prefix) '
NUMBER_SUFFIX=' (suffix)'

MSGBOX TEXT(number)

= hexadezimal (radix 16)
NUMBER_RADIX=16
NUMBER_PREFIX='0x'
NUMBER_SUFFIX=''

MSGBOX TEXT(number)

= hexadezimal (radix 16), alternate output format
NUMBER_RADIX=16
NUMBER_PREFIX=''
NUMBER_SUFFIX='h'

MSGBOX TEXT(number)


top bottom
NUMBER TEXT2DATA(data, index, count)
Parameters:

data: an expression of type TEXT
index, count: expressions of type SIGBYTE

more...

less...

The TEXT2DATA() function is the counterpart of the DATA2TEXT() function. It is used to extract numeric values from tables created by DATA2TEXT().

data contains the binary data values.

index is the index to the data TEXT string, where data extraction starts, multiplied by the count parameter value.

count is either the negative value of a data type constant or the amount of data to be extracted (deprecated). The type of the data returned by TEXT2DATA() depends on this parameter.
See also: DATA2TEXT(), TEXT2DATABE().
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1

VAR ptable TEXT, num SIGQWORD

= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
  CONCAT ptable, DATA2TEXT(SIGQWORD(num))
  INC num, num
ENDLOCAL


VAR inp TEXT q SIGQWORD power SIGQWORD

LET num = 1
LET ptable = ''
LOOP create_table 63

REPEAT
  REPEAT
    REPEAT
      LET inp = INPUT('Enter a number between 0 and 62')
    UNTIL ISNUMBER(inp)
    LET q = SIGQWORD(inp)
  UNTIL (q < 63) AND (q >= 0)

  = power values are stored as SIGQWORD, so SIGQWORD_SIZE or -SIGQWORD_DATA must be used
  = to access the correct data
  power = TEXT2DATA(ptable, q, -SIGQWORD_DATA)
  MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))

UNTIL 0

top bottom
NUMBER TEXT2DATABE(data, index, count)
Parameters:

data: an expression of type TEXT
index, count: expressions of type LONGWORD

more...

less...

The TEXT2DATABE() function is the counterpart of the DATA2TEXTBE() function. It is used to extract numeric values from tables created by DATA2TEXTBE().

data contains the binary data values in BIG ENDIAN format.

index is the index to the data TEXT string, where data extraction starts, multiplied by the count parameter value.

count is either the negative value of a data type constant or the amount of data to be extracted (deprecated). The type of the data returned by TEXT2DATABE() depends on this parameter.
See also: DATA2TEXTBE(), TEXT2DATA().
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1

VAR ptable TEXT, num SIGQWORD

= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
  CONCAT ptable, DATA2TEXTBE(SIGQWORD(num))
  INC num, num
ENDLOCAL


VAR inp TEXT q SIGQWORD power SIGQWORD

LET num = 1
LET ptable = ''
LOOP create_table 63

REPEAT
  REPEAT
    REPEAT
      LET inp = INPUT('Enter a number between 0 and 62')
    UNTIL ISNUMBER(inp)
    LET q = SIGQWORD(inp)
  UNTIL (q < 63) AND (q >= 0)

  = power values are stored as SIGQWORD, so SIGQWORD_SIZE or -SIGQWORD_DATA must be used
  = to access the correct data
  power = TEXT2DATABE(ptable, q, -SIGQWORD_DATA)
  MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))

UNTIL 0

top bottom
TEXT TEXTCHOP(string [, flags])
Parameters:

string, flags: expressions of type TEXT

more...

less...

TEXTCHOP() is used to remove preceding and/or trailing whitespaces from a string (whitespaces are characters from 0x00..0x20).

string is the text expression to be chopped.

The optional flags parameter tells the function where to remove whitespaces:
Sample:
VAR in TEXT, out TEXT

= generate a string with garbage at beginning and end
in = "\t STRING\n\r"
= in: (0x09)(0x20)"STRING"(0x0a)(0x0d)

out = TEXTCHOP(in) := (or out = TEXTCHOP(in,"pt"))
= out now contains "STRING"

out = TEXTCHOP(in, "p")
= out now contains "STRING"(0x0a)(0x0d)

out = TEXTCHOP(in, "t")
= out now contains (0x09)(0x20)"STRING"

top bottom
TEXT TEXTCONVERT(string, source, target)
Parameters:

string: an expression of type TEXT
source, target: expressions of type BYTE

more...

less...

TEXTCONVERT() is used to convert the text string from character translation source to character translation target.

source and target can be one of the following values (symbols are defined in DEF.MPS):
Sample:
= include the TEXTCONVERT_... symbols
INCLUDE 'DEF.MPS'

VAR sAnsi TEXT, sEbcdic TEXT, sUnicode Text

= store a text
sAnsi = 'Hello world!'

= now convert the text from ansi to ebcdic
sEbcdic = TEXTCONVERT(sAnsi, TEXTCONVERT_ANSI, TEXTCONVERT_EBCDIC)
= now the text is stored in ebcdic cp 38 in sEbcdic

= now convert the text from ebcdic to unicode
sUnicode = TEXTCONVERT(sEbcdic, TEXTCONVERT_EBCDIC, TEXTCONVERT_UNICODE)
= now the text is stored in unicode little endian in sUnicode

= now convert the text back from unicode to ansi
sAnsi = TEXTCONVERT(sUnicode, TEXTCONVERT_UNICODE, TEXTCONVERT_ANSI)
= now the text 'Hello world!' should be stored in ansi in sAnsi

= show whether it works (many special and unicode characters cannot be converted correctly, but
= normal ascii characters should work)
MSGBOX sAnsi

top bottom
TEXT TEXTCOPY(string, start [, count])
Parameters:

string: an expression of type TEXT
start, count: expressions of type LONGWORD

more...

less...

The TEXTCOPY() function returns a part of the value of string.

start is the index to the first character of string to copy (the first char is at index 1, not 0!).

count is the amount of characters to copy. If this parameter is omitted, all characters from start up to the last character are copied.
See also: TEXTLEN(), TEXTPOS(), TEXTCUT().
Sample:
var txt1 TEXT, txt2 TEXT
txt1="This is a text"

txt2=TEXTCOPY(txt1, 6, 2)
= txt2 now contains the text "is"

MSGBOX txt2

top bottom
TEXT TEXTCUT(stringref, start [, count])
Parameters:

stringref: an expression of type VARREF
start, count: expressions of type LONGWORD

more...

less...

The TEXTCUT() function extracts a part of the value of the TEXT variable referenced by stringref and returns the extracted text.

start is the index to the first character of the TEXT variable referenced by stringref to extract (the first char is at index 1, not 0!).

count is the amount of characters to extract. If this parameter is omitted, all characters from start up to the last character are extracted.
See also: TEXTCOPY().
Sample:
var txt1 TEXT, txt2 TEXT
txt1="This is a text"

txt2=TEXTCUT(@txt1, 6, 2)
= txt2 now contains the text "is", txt1 now contains "This  a text"

MSGBOX txt2
MSGBOX txt1

top bottom
LONGWORD TEXTLEN(string)
Parameters:

string: an expression of type TEXT

more...

less...

TEXTLEN() returns the length (in characters) of string.
See also: TEXTCOPY(), TEXTPOS().
Sample:
var inp TEXT

REPEAT
  inp=INPUT('Enter a text consisting of exactly six characters')
UNTIL TEXTLEN(inp) == 6

top bottom
TEXT TEXTLINE(lines, index)*
Parameters:

lines: an expression of type TEXT
index: an expression of type LONGWORD

more...

less...

TEXTLINE() returns the line index of the text lines. This function is used to work with text files (TEXT variables that contain multiple lines separated by newline characters (chr(10) and/or chr(13)). The first line is at index 0.
See also: TEXTLINECOUNT().
Sample:
var str TEXT line TEXT

str="Line 1\nLine 2\rLine 3":= supports different newline characters

= display the third number (as the function is zero-based, use index 2!)
line=TEXTLINE(str, 2)

MSGBOX ("Third line is '"+line+"'")

top bottom
LONGWORD TEXTLINECOUNT(lines)*
Parameters:

lines: an expression of type TEXT

more...

less...

TEXTLINECOUNT() returns the number of lines stored in the text lines. Lines are separated by newline characters (chr(10) and/or chr(13)).
See also: TEXTLINE().
Sample:
var str TEXT count LONGWORD

str="Line 1"+CHAR(0x0d)+CHAR(0x0a)+"Line 2"+CHAR(0x0d)+"Line 3"+CHAR(0x0a)+"Line 4":= supports 0d0a, 0d and 0a

= count the number of lines in str
count=TEXTLINECOUNT(str)

MSGBOX (DEC(count)+' lines in text')

top bottom
TEXT TEXTLOWER(string)
Parameters:

string: an expression of type TEXT

more...

less...

TEXTLOWER() converts all characters in string to lower case and returns the converted TEXT.
See also: TEXTUPPER().
Sample:
var str TEXT

str="Lower Case"

str=TEXTLOWER(str)
= str is set to "lower case" now

MSGBOX str

top bottom
LONGWORD TEXTPOS(substr, string)
Parameters:

substr, string: expressions of type TEXT

more...

less...

TEXTPOS() returns the index of the first occurance of the string substr in string. If substr is not contained in string, 0 is returned.
See also: TEXTCOPY(), TEXTLEN().
Sample:
var inp TEXT

REPEAT
  inp=INPUT('Enter a string that contains the text "hex"')
UNTIL TEXTPOS("hex",inp) > 0

top bottom
TEXT TEXTUPPER(string)
Parameters:

string: an expression of type TEXT

more...

less...

TEXTUPPER() converts all characters in string to upper case and returns the converted TEXT.
See also: TEXTLOWER().
Sample:
var str TEXT

str="Upper Case"

str=TEXTUPPER(str)
= str is set to "UPPER CASE" now

MSGBOX str

top bottom
SIGQWORD TRUNC(number)*
Parameters:

number: a numeric expression

more...

less...

TRUNC() returns the ordinal value of the argument number, rounded towards 0.
See also: CEIL(), FLOOR(), FRAC(), INT(), ROUND().
Sample:
MSGBOX (DEC(TRUNC(2.0))):= results in "2"
MSGBOX (DEC(TRUNC(2.9999))):= results in "2"
MSGBOX (DEC(TRUNC(-2.9999))):= results in "-2"

top bottom
BYTE TYPEOF(expr)
Parameters:

expr: an expression

more...

less...

TYPEOF() returns the data type of expr.

An expression has one of the following data types:
See also: Data types.
Sample:
= show data type example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1

VAR output TEXT

= get a textual data type representation
LOCAL getdatatype
  VAR stack VARREF
  VAR type SIGBYTE
  VAR types TEXT
  LET types = <<
none
character
unsigned byte
unsigned word
unsigned long
signed quad
text
file
variable reference
single float
double float
extended float
comp float
signed byte
signed word
signed long
>>

  POP stack
  LET type = TYPEOF(DEREF(stack))
  IF ((type <= SIGLONGWORD_DATA) AND (type >= 0))
    RETURN TEXTLINE(types, type)
  ENDIF
  RETURN "unknown"

ENDLOCAL


LOCAL sub_tp
  VAR msg TEXT varn TEXT
  LET msg = #getdatatype
  POP varn
  CONCAT output, (varn+" is of type "+msg+"\n")
ENDLOCAL


VAR charV CHAR, byteV BYTE, wordV WORD, longwordV LONGWORD
VAR sigqwordV SIGQWORD, textV TEXT, fileV FILE, refV VARREF, noneV NONE
VAR singleV SINGLE, doubleV DOUBLE, extendedV EXTENDED, compV COMP
VAR sigbyteV SIGBYTE, sigwordV SIGWORD, siglongwordV SIGLONGWORD


call sub_tp, 'charV', @charV
call sub_tp, 'byteV', @byteV
call sub_tp, 'wordV', @wordV
call sub_tp, 'longwordV', @longwordV

call sub_tp, 'sigqwordV', @sigqwordV
call sub_tp, 'textV', @textV
call sub_tp, 'fileV', @fileV
call sub_tp, 'refV', @refV
call sub_tp, 'noneV', @noneV

call sub_tp, 'singleV', @singleV
call sub_tp, 'doubleV', @doubleV
call sub_tp, 'compV', @compV
call sub_tp, 'extendedV', @extendedV

call sub_tp, 'sigbyteV', @sigbyteV
call sub_tp, 'sigwordV', @sigwordV
call sub_tp, 'siglongwordV', @siglongwordV

TEXTBOX output

top bottom
WORD WORD(expr)
Parameters:

expr: an expression

more...

less...

The WORD() function is used to convert the expression expr to the WORD data type.

If expr is a numeric or CHAR expression, the lowest 16 bits of its ordinal value are returned.

If expr is of type TEXT, Tiny Hexer tries to convert the text string to a number. If conversion fails, an error is raised. If conversion succeeds, the lowest 16 bits of the converted number are returned.
See also: Data types.
Sample:
= convert a text to a word number
VAR inp TEXT w WORD

REPEAT
  inp = INPUT('Enter a numeric value')
UNTIL ISNUMBER(inp)

LET w = WORD(inp)

= output hexadecimal
MSGBOX ('The number you entered was (hex): '+HEX(w))

top bottom
mirkes.de's Tiny Hexer, Copyright ⌐ Markus Stephany. All rights reserved.